HealthCategorySample PRO
The HealthCategorySample class represents an individual category-based health record, such as a sleep session, menstrual flow level, or a test result. These samples are used to store discrete events or conditions over time, usually characterized by a start and end date along with a categorical value.
Overview
This class is suitable for:
- Tracking and analyzing time-bound health events (e.g., sleep analysis)
- Recording categorical values with a specific time interval (e.g., "present" or "not present")
- Manually creating samples for use with HealthKit-compatible export or analysis
Properties
Method: static create(...)
Creates a new HealthCategorySample instance using the specified parameters.
Signature
Parameters
Returns
- A
HealthCategorySampleinstance if the inputs are valid. nullif the parameters are invalid (e.g., value/type mismatch).
Usage Examples
1. Creating a Sleep Analysis Sample
2. Logging a Sexual Activity Event
3. Tracking Ovulation Test Result
Notes on value
The value field must be a valid enum value for the given category type. For example:
sleepAnalysismust useHealthCategoryValueSleepAnalysissexualActivitymust useHealthCategoryValuePresencemenstrualFlowmust useHealthCategoryValueSeverityovulationTestResultmust useHealthCategoryValueOvulationTestResult
If the value and type do not match, the sample creation will fail and return null.
